package com.wd.tw.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wd.common.core.domain.HttpResponse;
import com.wd.tw.service.EventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @className: AieController
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2025/1/8
 **/

@RestController
@Slf4j
public class AieController {

    @Resource
    EventService eventService;

    @RequestMapping("/aie/event")
    public HttpResponse test(@RequestParam("key") String key,
                             @RequestParam String json) {
        JSONObject jsonObj = JSONObject.parseObject(json);
        //775为心跳请求，忽略
        if (jsonObj.getInteger("msg_id") == 775) {
            return HttpResponse.success();
        }
        try {
            if (jsonObj.getJSONObject("data").getInteger("obj_label") == 2) {
                eventService.dealEvent(json);
            } else {
                log.info("do not have to  deal event:" + jsonObj.getJSONObject("data").getInteger("obj_label"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info(json);
        }
        return HttpResponse.success();
    }
}
